package com.runshu.newsmartark.mvp.model;

import com.runshu.newsmartark.base.MyApplication;
import com.runshu.newsmartark.common.ConstantUrl;
import com.runshu.newsmartark.dbutil.ProAllEntity;
import com.runshu.newsmartark.entity.CheckInventoryEntity;
import com.runshu.newsmartark.entity.ConfirmStockEntity;
import com.runshu.newsmartark.mvp.contract.ConfirmStockContract;
import com.runshu.newsmartark.network.netbean.HttpRequestParamsBuilder;
import com.runshu.newsmartark.network.netbean.ResponseBean;
import com.runshu.newsmartark.network.netinterface.BaseCallBack;

import java.util.List;

/**
 * Demo class
 *
 * @author yu
 * @date 2020/10/28
 * @decs：
 */

public class ConfirmStockModel extends BaseModel implements ConfirmStockContract.Model {

    @Override
    public void getConfirmStock(String macAddress, String userCode, List<String> refIds, String type, BaseCallBack baseCallBack) {
        HttpRequestParamsBuilder builder = new HttpRequestParamsBuilder();
        builder.putParams( "macAddress", macAddress );
        builder.putParams( "userCode", userCode );
        builder.putParams( "refIds", refIds );
        builder.putParams( "refIds", refIds );
        builder.putParams( "type", type );
        super.initDataFromServer( ConstantUrl.CONFIRM_TakeStock, builder.build(), ConfirmStockEntity.class, ResponseBean.RES_DATATYPE_BEAN, baseCallBack );

    }

    @Override
    public void getGoodsBySerno(List<String> refIds, BaseCallBack baseCallBack) {
        HttpRequestParamsBuilder builder = new HttpRequestParamsBuilder();
        StringBuilder urlQuery = new StringBuilder();
        urlQuery.append( ConstantUrl.GET_GOODS_BY_SERIALNO );
        urlQuery.append( "?" );
        urlQuery.append( "productIds=" );
        for (int i = 0; i < refIds.size(); i++) {
            try {
                Integer num = Integer.valueOf( refIds.get( i ) );
                urlQuery.append( num );
            } catch (Exception e) {
                continue;
            }

            if (i != (refIds.size() - 1)) {
                urlQuery.append( "," );
            }
        }
        super.initDataFromServer( urlQuery.toString(), builder.build(), ProAllEntity.class, ResponseBean.RES_DATATYPE_BEANLIST,
                baseCallBack );
    }

    @Override
    public void checkInventory(String customerId, String hospitalId, String hwMac, List<String> rfidsList,  int afreshType,BaseCallBack baseCallBack) {
        HttpRequestParamsBuilder builder = new HttpRequestParamsBuilder();
        builder.putParams( "customerId", customerId );
        builder.putParams( "hospitalId", hospitalId );
        builder.putParams( "hwMac", hwMac );
        builder.putParams( "rfidsList", rfidsList );
        builder.putParams( "afreshType", afreshType );
        builder.putParams( "afreshType", afreshType );
        builder.putParams( "userCode",  MyApplication.getUserInfoGlob().getUserCode());
        builder.putParams( "userName",  MyApplication.getUserInfoGlob().getUserName());
        super.initDataFromServer( ConstantUrl.GET_checkInventory, builder.build(), CheckInventoryEntity.class, ResponseBean.RES_DATATYPE_BEAN, baseCallBack );

    }
}